/*
 * Copyright (c) 2016, Freescale Semiconductor, Inc.
 * Copyright 2016 NXP
 * All rights reserved.
 *
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
#include "snvs_hp_rtc.h"


/*******************************************************************************
 * Definitions
 ******************************************************************************/
#define kCLOCK_SnvsHp0 kCLOCK_SnvsHp
#define EXAMPLE_SNVS_IRQn SNVS_HP_WRAPPER_IRQn

/*******************************************************************************
 * Prototypes
 ******************************************************************************/

/*******************************************************************************
 * Variables
 ******************************************************************************/
 snvs_hp_rtc_datetime_t rtcDate;

/*******************************************************************************
 * Code
 ******************************************************************************/
/*!
 * @brief Main function
 */


int snvs_hp_rtc(void)
{
    uint32_t sec;
    uint8_t index;
    snvs_hp_rtc_config_t snvsRtcConfig;

    /* Init SNVS */
    /*
     * snvsConfig->rtccalenable = false;
     * snvsConfig->rtccalvalue = 0U;
     * snvsConfig->srtccalenable = false;
     * snvsConfig->srtccalvalue = 0U;
     * snvsConfig->PIFreq = 0U;
     */
    SNVS_HP_RTC_GetDefaultConfig(&snvsRtcConfig);
    SNVS_HP_RTC_Init(SNVS, &snvsRtcConfig);

    /* Set a start date time and start RT */
    rtcDate.year   = 2020;
    rtcDate.month  = 1U;
    rtcDate.day    = 10U;
    rtcDate.hour   = 12U;
    rtcDate.minute = 46;
    rtcDate.second = 0;

    /* Set RTC time to default time and date and start the RTC */
    SNVS_HP_RTC_SetDatetime(SNVS, &rtcDate);
    SNVS_HP_RTC_StartTimer(SNVS);
    //SNVS_HP_RTC_GetDatetime(SNVS, &rtcDate);
		return 0;
}

void gettimeofday(struct timeval*tv, struct timezone *tz)
{
	SNVS_HP_RTC_GetDatetime(SNVS, &rtcDate);
	tv->tv_sec = SNVS_HP_ConvertDatetimeToSeconds(&rtcDate);
	tv->tv_usec = 200;
}



